<!-- HTML header for doxygen 1.8.6-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.13"/>
<title>OpenCV: How to run custom OCR model</title>
<link href="../../opencv.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="../../tutorial-utils.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
//<![CDATA[
MathJax.Hub.Config(
{
  TeX: {
      Macros: {
          matTT: [ "\\[ \\left|\\begin{array}{ccc} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{array}\\right| \\]", 9],
          fork: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ \\end{array} \\right.", 4],
          forkthree: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ \\end{array} \\right.", 6],
          forkfour: ["\\left\\{ \\begin{array}{l l} #1 & \\mbox{#2}\\\\ #3 & \\mbox{#4}\\\\ #5 & \\mbox{#6}\\\\ #7 & \\mbox{#8}\\\\ \\end{array} \\right.", 8],
          vecthree: ["\\begin{bmatrix} #1\\\\ #2\\\\ #3 \\end{bmatrix}", 3],
          vecthreethree: ["\\begin{bmatrix} #1 & #2 & #3\\\\ #4 & #5 & #6\\\\ #7 & #8 & #9 \\end{bmatrix}", 9],
          cameramatrix: ["#1 = \\begin{bmatrix} f_x & 0 & c_x\\\\ 0 & f_y & c_y\\\\ 0 & 0 & 1 \\end{bmatrix}", 1],
          distcoeffs: ["(k_1, k_2, p_1, p_2[, k_3[, k_4, k_5, k_6 [, s_1, s_2, s_3, s_4[, \\tau_x, \\tau_y]]]]) \\text{ of 4, 5, 8, 12 or 14 elements}"],
          distcoeffsfisheye: ["(k_1, k_2, k_3, k_4)"],
          hdotsfor: ["\\dots", 1],
          mathbbm: ["\\mathbb{#1}", 1],
          bordermatrix: ["\\matrix{#1}", 1]
      }
  }
}
);
//]]>
</script><script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<!--#include virtual="/google-search.html"-->
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="../../opencv-logo-small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">OpenCV
   &#160;<span id="projectnumber">4.5.2</span>
   </div>
   <div id="projectbrief">Open Source Computer Vision</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.13 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
$(function() {
  initMenu('../../',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="../../d9/df8/tutorial_root.html">OpenCV Tutorials</a></li><li class="navelem"><a class="el" href="../../d2/d58/tutorial_table_of_content_dnn.html">Deep Neural Networks (dnn module)</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">How to run custom OCR model </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><b>Prev Tutorial:</b> <a class="el" href="../../dc/db1/tutorial_dnn_custom_layers.html">Custom deep learning layers support</a></p>
<p><b>Next Tutorial:</b> <a class="el" href="../../d4/d43/tutorial_dnn_text_spotting.html">High Level API: TextDetectionModel and TextRecognitionModel</a></p>
<table class="doxtable">
<tr>
<th align="right"></th><th align="left"></th></tr>
<tr>
<td align="right">Original author </td><td align="left">Zihao Mu </td></tr>
<tr>
<td align="right">Compatibility </td><td align="left">OpenCV &gt;= 4.3 </td></tr>
</table>
<h2>Introduction</h2>
<p>In this tutorial, we first introduce how to obtain the custom OCR model, then how to transform your own OCR models so that they can be run correctly by the opencv_dnn module. and finally we will provide some pre-trained models.</p>
<h2>Train your own OCR model</h2>
<p><a href="https://github.com/zihaomu/deep-text-recognition-benchmark">This repository</a> is a good start point for training your own OCR model. In repository, the MJSynth+SynthText was set as training set by default. In addition, you can configure the model structure and data set you want.</p>
<h2>Transform OCR model to ONNX format and Use it in OpenCV DNN</h2>
<p>After completing the model training, please use <a href="https://github.com/zihaomu/deep-text-recognition-benchmark/blob/master/transform_to_onnx.py">transform_to_onnx.py</a> to convert the model into onnx format.</p>
<h4>Execute in webcam</h4>
<p>The Python version example code can be found at <a href="https://github.com/opencv/opencv/blob/master/samples/dnn/text_detection.py">here</a>.</p>
<p>Example: </p><div class="fragment"><div class="line">$ text_detection -m=[path_to_text_detect_model] -ocr=[path_to_text_recognition_model]</div></div><!-- fragment --><h2>Pre-trained ONNX models are provided</h2>
<p>Some pre-trained models can be found at <a href="https://drive.google.com/drive/folders/1cTbQ3nuZG-EKWak6emD_s8_hHXWz7lAr?usp=sharing">https://drive.google.com/drive/folders/1cTbQ3nuZG-EKWak6emD_s8_hHXWz7lAr?usp=sharing</a>.</p>
<p>Their performance at different text recognition datasets is shown in the table below:</p>
<table class="doxtable">
<tr>
<th>Model name </th><th>IIIT5k(%) </th><th>SVT(%) </th><th>ICDAR03(%) </th><th>ICDAR13(%) </th><th>ICDAR15(%) </th><th>SVTP(%) </th><th>CUTE80(%) </th><th>average acc (%) </th><th>parameter( x10^6 )  </th></tr>
<tr>
<td>DenseNet-CTC </td><td>72.267 </td><td>67.39 </td><td>82.81 </td><td>80 </td><td>48.38 </td><td>49.45 </td><td>42.50 </td><td>63.26 </td><td>0.24 </td></tr>
<tr>
<td>DenseNet-BiLSTM-CTC </td><td>73.76 </td><td>72.33 </td><td>86.15 </td><td>83.15 </td><td>50.67 </td><td>57.984 </td><td>49.826 </td><td>67.69 </td><td>3.63 </td></tr>
<tr>
<td>VGG-CTC </td><td>75.96 </td><td>75.42 </td><td>85.92 </td><td>83.54 </td><td>54.89 </td><td>57.52 </td><td>50.17 </td><td>69.06 </td><td>5.57 </td></tr>
<tr>
<td>CRNN_VGG-BiLSTM-CTC </td><td>82.63 </td><td>82.07 </td><td>92.96 </td><td>88.867 </td><td>66.28 </td><td>71.01 </td><td>62.37 </td><td>78.03 </td><td>8.45 </td></tr>
<tr>
<td>ResNet-CTC </td><td>84.00 </td><td>84.08 </td><td>92.39 </td><td>88.96 </td><td>67.74 </td><td>74.73 </td><td>67.60 </td><td>79.93 </td><td>44.28 </td></tr>
</table>
<p>The performance of the text recognition model were tesred on OpenCV DNN, and does not include the text detection model.</p>
<h4>Model selection suggestion:</h4>
<p>The input of text recognition model is the output of the text detection model, which causes the performance of text detection to greatly affect the performance of text recognition.</p>
<p>DenseNet_CTC has the smallest parameters and best FPS, and it is suitable for edge devices, which are very sensitive to the cost of calculation. If you have limited computing resources and want to achieve better accuracy, VGG_CTC is a good choice.</p>
<p>CRNN_VGG_BiLSTM_CTC is suitable for scenarios that require high recognition accuracy. </p>
</div></div><!-- contents -->
<!-- HTML footer for doxygen 1.8.6-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Fri Apr 2 2021 11:36:34 for OpenCV by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="../../doxygen.png" alt="doxygen"/>
</a> 1.8.13
</small></address>
<script type="text/javascript">
//<![CDATA[
addTutorialsButtons();
//]]>
</script>
</body>
</html>
